// SETUP

#include endepisodegraphics_jester.txt

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function spinthewheel(sign, wheel) {
  var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.hide();
	
  wheel.x = 30;
  wheel.y = -30;
  play("spinthewheel");
	var s = wheel.show("spin1");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	wheel.hide();
}

// ACTORS

actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
actor("Inventor", 150, screenheight - 100, 0xffe48d, LEFT, BOTTOM, "chat_inventor", "characters/inventor/charicon_inventor");
// INTRO

play("music_cutscene_lesscheery");

changebackground("intro_sign");

sign.y = -screenheight;
jester.y = -screenheight;
sign.show("loop");
jester.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(jester, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();

wait(1.5);

jester.show("talking");
actor("Jester", screenwidthmid + 200, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "You’re doing so well! Congratulations!");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Welcome to the VICTORY STAGE!");
actor("Jester", screenwidthmid, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "We’re going to SPIN THE WHEEL to see whether|you’ve won yourself a nice little prize -");
speak("Jester", "- what was it you were after again?");
jester.show("idle");

speak("Inventor", "I want to have complete understanding of everything in the universe!");

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Ah, don’t we all?");
actor("Jester", screenwidthmid + 200, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Right, let’s SPIN THE WHEEL and see...");
jester.show("idle");

jester.hide();

spinthewheel(sign, wheel);

signanimate(sign);

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "...nope, it looks like you’re|out of luck this time.");
speak("Jester", "But maybe next episode!");
jester.show("idle");

speak("Inventor", "...can you at least tell me how the wheel works? It’s so cool!");

jester.show("talking");
actor("Jester", screenwidthmid + 400, 100, Col.multiplylightness(Col.RED, 1.25), LEFT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "Hahaha no I definitely can’t!");
speak("Jester", "CUT. Did anyone hear me? I|said CUT. Stop filming!");
jester.show("idle");

gamecompletefromcutscene();
